package com.learn.jackson.annotation.jsonCreator;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author HuangChao
 * @since 2025/6/8 21:02
 */
@Data
@EqualsAndHashCode
public class JsonCreatorEntity {

    private final Long id;
    private final String name;

    @JsonCreator
    public JsonCreatorEntity(@JsonProperty("id") Long id, @JsonProperty("name2") String name) {
        this.id = id;
        this.name = name;
    }

    // 两者同时存在则  构造器生效
    @JsonCreator
    public static JsonCreatorEntity create(@JsonProperty("id") Long id, @JsonProperty("name") String name) {
        return new JsonCreatorEntity(id, name);
    }
}
